﻿using System;

public class CountNumberInArray
{
    //Exercise 4.
    //Write a method that counts how many times given number appears in given array. 
    //Write a test program to check if the method is working correctly.

    //Sample: int[] array = new int[] { 2, 4, 7, 2, 2, 7, 15, 56, -3, 15, 2, 2, 4 };


    public static int number;
    public static int count;

    static void Main()
    {
        //enter the length and the elements of the array from the console
        Console.Write("Type the length of the array:  ");
        int length = int.Parse(Console.ReadLine());
        Console.WriteLine("Type the elements of the array:");
        int[] array = new int[length];
        for (int i = 0; i < length; i++)
        {
            array[i] = int.Parse(Console.ReadLine());
        }
        
        
        Console.Write("Enter a number: ");
        int number = int.Parse(Console.ReadLine());
        //int count = 0;
        Count(array, number);
        Console.WriteLine("The number {0} appears {1} times in the array.", number, count);
        Console.WriteLine(count);
    }

    public static int Count(int[] array, int number)
    {
        //int number = int.Parse(Console.ReadLine());
        count = 0;
        for (int i = 0; i < array.Length; i++)
        {
            if (number == array[i])
            {
                count++;
            }
        }
        return count;
        
    }
}

